let readlineSync = require('readline-sync');
// 处理输入的字符串成对象
function storeInfo(studentInfo){
    let arr = studentInfo.split(",");
    let student_obj = {name:arr[0],id:arr[1],ethnic:arr[2],classs:arr[3]};
    // student_obj.name = arr[0];
    // student_obj.id = arr[1];
    // student_obj.ethnic = arr[2];
    for(let i=4;i<arr.length;i++){
        let item = arr[i].split(":");
        student_obj[item[0]] = item[1];
    }
    return student_obj;
}
// 添加学生信息
module.exports = function addStudent(studentInfo) {
    let match = /^([\u4e00-\u9fa5]{1,4}),([0-9]{4}),([\u4e00-\u9fa5]),([0-9]{1,2})+/;
    while(!match.test(studentInfo)){
        console.log(`请按正确的格式输入（格式：姓名, 学号, 学科: 成绩, ...）：`);
        studentInfo = readlineSync.question(``);        
    }
    let student_obj = storeInfo(studentInfo);
    console.log(`学生${student_obj.name}的成绩被添加`);
    return student_obj;
}
